home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-09 | 18.3 KB | 670 lines | [TEXT/MPS ] |
- /*
- Copyright: © 1993-1994 by Apple Computer, Inc., all rights reserved.
- */
-
- // ----------------------------------------------------------------------------------------
- // I M P O R T
- // ----------------------------------------------------------------------------------------
- NamesImport := func( textFrame, store, importNotes )
- begin
- local soupFrame, error;
-
- soupFrame := {};
-
- soupFrame.cardType := 0;
-
- if (textFrame.cardType) then
- begin
- local temp := FindStringInArray(editTypes.cardType.choices, textFrame.cardType);
- if temp then
- soupFrame.cardType := temp;
- end;
-
- if (textFrame.honorific) then
- begin
- if (soupFrame.name = nil) then
- soupFrame.name := {class:'person};
- soupFrame.name.honorific := textFrame.honorific;
- end;
-
- if (textFrame.firstName) then
- begin
- if (soupFrame.name = nil) then
- soupFrame.name := {class:'person};
- soupFrame.name.first := textFrame.firstName;
- end;
-
- if (textFrame.lastname) then
- begin
- if (soupFrame.name = nil) then
- soupFrame.name := {class:'person};
- soupFrame.name.last := SetClass (textFrame.lastname, 'name);
- end;
-
- if (textFrame.title) then
- begin
- if (soupFrame.name = nil) then
- soupFrame.name := {class:'person};
- soupFrame.name.title := textFrame.title;
- end;
-
- if (textFrame.company) then
- soupFrame.company := SetClass (textFrame.company,'company);
-
- if (textFrame.address) then
- begin
- soupFrame.address := textFrame.address;
- SetClass(soupFrame.address,'address);
- end;
-
- if (textFrame.address2) then
- begin
- soupFrame.address2 := textFrame.address2;
- SetClass(soupFrame.address2,'address);
- end;
-
- if (textFrame.city) then
- soupFrame.city := textFrame.city;
-
- if (textFrame.region) then
- soupFrame.region := textFrame.region;
-
- if (textFrame.postalcode) then
- soupFrame.postal_code := textFrame.postalcode;
-
- if (textFrame.country) then
- soupFrame.country := textFrame.country;
-
- if (textFrame.email) then
- soupFrame.email := textFrame.email;
-
- local tPhones, tPhoneTypes, i, temp, foundType;
-
- tPhones := '[phone1,phone2,phone3,phone4];
- tPhoneTypes := '[phone1type,phone2type,phone3type,phone4type];
- foundType := nil;
-
- soupFrame.phones := [];
- for i := 0 to 3 do
- begin
- if (textFrame.(tPhones[i])) then
- begin
- temp := textFrame.(tPhones[i]);
- if temp then
- begin
- local moniker := textFrame.(tPhoneTypes[i]);
-
- local class := 'phone; // default to phone
- if moniker then
- begin
- local index := FindStringInArray (editTypes.phoneType.choices, moniker);
- if index <> nil then
- class := phoneClasses[index];
- end;
- AddArraySlot(soupFrame.phones, SetClass( temp, class) );
- end;
- end;
- end;
-
- if (textFrame.birthday) then
- soupFrame.bday := StringToDate(textFrame.birthday);
-
- if (textFrame.labels and (StrLen(textFrame.labels) > 0)) then
- soupFrame.labels := MakeSymbol (textFrame.labels);
-
- if textFrame.sorton Exists then
- begin
- if StrEqual(textFrame.sorton, :getSortonString ('company)) then
- begin
- if soupFrame.company then
- soupFrame.sorton := soupFrame.company;
- else
- soupFrame.sorton := SetClass( Clone(""), 'company );
- end;
- else
- if StrEqual(textFrame.sorton, :getSortonString ('name)) then
- begin
- if (soupFrame.name <> nil) and (soupFrame.name.last <> nil) then
- soupFrame.sorton := soupFrame.name.last;
- end;
- end;
- if soupFrame.sorton = nil then
- soupFrame.sorton := SetClass( Clone(""), 'name );
-
- if (importNotes <> nil) then
- begin
- if (textFrame.notes <> nil) and (store <> nil) then
- soupFrame.notes := StringToParagraphArray( store, textFrame.notes, kWSforNamesNote);
- end;
- else if textFrame.originalFrame and textFrame.originalFrame.notes then
- soupFrame.notes := textFrame.originalFrame.notes;
-
- soupFrame;
- end;
-
- //-------------------------------------------------------------------------------------------------
- // M E T A D A T A
- //-------------------------------------------------------------------------------------------------
- CardFileMeta := {
- soup: "Names",
- name: "Name File",
- version: 2,
- soupInfo: {applications: ['cardFile], itemNames: ["name", "names"] },
- soupIndicies: [{structure: 'slot, path: 'sorton, type: 'String}],
-
- getLocalizedLabel: func (slot)
- begin
- local localeBundle := GetLocale();
- return localeBundle.(slot);
- end,
-
- attributeFunctions: {
- cityLabel: func ()
- return :GetLocalizedLabel('cityLabel),
- regionLabel: func ()
- return :GetLocalizedLabel('regionLabel),
- postalCodeLabel: func ()
- return :GetLocalizedLabel('postalCodeLabel),
- citySize: func ()
- begin // account for locale
- local len := strlen(:GetLocalizedLabel('regionLabel));
- if len = 5 then return 27;
- else if len = 6 then return 25;
- else return 23;
- end,
- postalCodeSize: func ()
- begin
- local len := strlen(:GetLocalizedLabel('postalCodeLabel));
- if len = 8 then return 20;
- else if len = 9 then return 19;
- else return 18;
- end,
- },
-
- // make sure there's a sorton slot since it's indexed
- newEntry: {sortOn: SetClass(Clone(""), 'name), phones: []},
-
- defaultDefinitions: {
- honorific: {label:"Ms./Mr.", size:5, path: [pathExpr: 'name, 'honorific]},
- firstname: {label:"First Name", path: [pathExpr: 'name, 'first]},
- lastname: {label:"Last Name", path: [pathExpr: 'name, 'last]},
- title: {label:"Title", path: [pathExpr: 'name, 'title]},
- company: {label:"Company"},
- address: {label:"Address Line 1"},
- address2: {label:"Address Line 2"},
- city: {label:'cityLabel},
- region: {label:'regionLabel},
- postalCode: {label:'postalCodeLabel, path: 'postal_code, justify:'right},
- country: {label:"Country"},
- email: {label:"E-Mail"},
- phone1: {label:"Phone 1", compareScript: 'phone, type:'phone, justify:'right},
- phone1type: {label:"Key 1", compareScript: 'phonetype, type:'phoneType},
- phone2: {label:"Phone 2", compareScript: 'phone, type:'phone, justify:'right},
- phone2type: {label:"Key 2", compareScript: 'phonetype, type:'phoneType},
- phone3: {label:"Phone 3", compareScript: 'phone, type:'phone, justify:'right},
- phone3type: {label:"Key 3", compareScript: 'phonetype, type:'phoneType},
- phone4: {label:"Phone 4", compareScript: 'phone, type:'phone, justify:'right},
- phone4type: {label:"Key 4", compareScript: 'phonetype, type:'phoneType},
- birthday: {label:"Birthday", type:'date, path: 'bday},
- labels: {label:"Folder", type:'folder, path: 'labels},
- sorton: {type:'sortonType, compareScript: 'sorton},
- cardType: {type:'cardType, compareScript: 'cardType},
- notes: {label: "Notes", type: 'text},
- },
-
- displayInfo: [
- {slot:'honorific, hidden:TRUE},
- 'lastname,
- 'firstname,
- {slot:'title, hidden:TRUE},
- {slot:'company, size:20},
- {slot:'address, size:20, hidden:TRUE},
- {slot:'address2, size:20, hidden:TRUE},
- {slot:'city, size:20, hidden:TRUE},
- {slot:'region, size:6, hidden:TRUE},
- {slot:'postalCode, size:10, hidden:TRUE},
- {slot:'country, size:6, hidden:TRUE},
- {slot:'email, size:20, hidden:TRUE},
- 'phone1,
- {slot:'phone1type, size:7},
- 'phone2,
- {slot:'phone2type, size:7},
- {slot:'phone3, hidden:TRUE},
- {slot:'phone3type, size:7, hidden:TRUE},
- {slot:'phone4, hidden:TRUE},
- {slot:'phone4type, size:7, hidden:TRUE},
- {slot:'birthday, size:12, hidden:TRUE},
- {slot:'labels, hidden:TRUE},
- {slot:'sorton, hidden:TRUE},
- {slot:'cardType, hidden:TRUE},
- {slot: 'notes, hidden: TRUE},
- ],
-
- editInfo: [
- {slot:'company, size:27},
- {slot:'sorton, sameline:TRUE},
- 'honorific,
- {slot:'firstname, size:15, sameline:TRUE, label: "Name"},
- {slot:'lastname, size:22, sameline:TRUE, label: ""},
- {slot:'title, size:50},
- {slot:'address, size:50, label: "Address"},
- {slot:'address2, size:50, label: ""},
- {slot:'city, size: 'citySize},
- {slot:'region, size:17, sameline:TRUE},
- {slot:'postalCode, size:'postalCodeSize},
- {slot:'country, size:21, sameline:TRUE},
- {slot:'phone1, size:27},
- {slot:'phone1Type, sameline:TRUE, label: ""},
- {slot:'phone2, size:27},
- {slot:'phone2Type, sameline:TRUE, label: ""},
- {slot:'phone3, size:27},
- {slot:'phone3Type, sameline:TRUE, label: ""},
- {slot:'phone4, size:27},
- {slot:'phone4Type, sameline:TRUE, label: ""},
- {slot:'email, size:27},
- {slot:'birthday, size:14, sameline:TRUE},
- 'labels,
- {slot:'cardType, sameline:TRUE, label: " Card Style"},
- {slot: 'notes, uneditable: true, size: 50},
- ],
- column0width: 7,
-
- exportInfo: [
- 'honorific,
- 'firstname,
- 'lastname,
- 'title,
- 'company,
- 'address,
- 'address2,
- 'city,
- 'region,
- 'postalCode,
- 'country,
- 'email,
- 'phone1,
- 'phone1type,
- 'phone2,
- 'phone2type,
- 'phone3,
- 'phone3type,
- 'phone4,
- 'phone4type,
- 'birthday,
- 'labels,
- 'sorton,
- 'cardType,
- 'notes
- ],
-
- editTypes: {
- phoneType: {
- type:'PICKLIST,
- choices:[
- "Phone",
- "Home",
- "Work",
- "Fax",
- "Car",
- "Beeper",
- "Mobile",
- "Other"
- ]
- },
- cardType: {
- type:'PICKLIST,
- label:"Card Style",
- choices:[
- "Style 1",
- "Style 2",
- "Style 3",
- "Style 4"
- ]
- },
- sortonType: {
- type:'PICKLIST,
- label:"List By",
- choices:[
- "Last name",
- "Company",
- ]
- },
- },
-
- phoneClasses:[ 'phone,
- 'homePhone,
- 'workPhone,
- 'faxPhone,
- 'carPhone,
- 'beeperPhone,
- 'mobilePhone,
- 'otherPhone
- ],
-
- compareScripts: {
- phone:
- func(entry, args)
- begin
- local result := nil;
- if entry.phones then
- begin
- local it := 3;
- if args.slotname = 'phone1 then
- it := 0;
- else if args.slotname = 'phone2 then
- it := 1;
- else if args.slotname = 'phone3 then
- it := 2;
- if it < Length(entry.phones) then
- begin
- result := entry.phones[it];
- end;
- end;
- return result;
- end,
- phoneType:
- func(entry, args)
- begin
- local result := nil;
- if entry.phones then
- begin
- local it := 3;
- if args.slotname = 'phone1type then
- it := 0;
- else if args.slotname = 'phone2type then
- it := 1;
- else if args.slotname = 'phone3type then
- it := 2;
- if it < Length(entry.phones) then
- begin
- result := :mapPhoneClassForExport(ClassOf(entry.phones[it]));
- end;
- end;
- return result;
- end,
- sorton:
- func(entry, args)
- begin
- local result := nil;
- if entry.sorton then
- result := :getSortonString(ClassOf(entry.sorton));
- return result;
- end,
- cardType:
- func(entry, args)
- return :exportCardType(entry.cardType);
- },
-
- // pass in 'name or 'company and this will return the proper string
- getSortonString: func (theSymbol)
- begin
- if theSymbol = 'company then
- return editTypes.sortonType.choices [1];
- else
- return editTypes.sortonType.choices [0];
- end,
-
- commonImport: NamesImport,
- tabImport: func (textFrame, store)
- :entryValidation (:commonImport (textFrame, store, true), store),
- editImport: func (textFrame, store)
- :entryValidation (:commonImport (textFrame, store, nil), store),
- // This one's just here for wizard import
- import: func (textFrame)
- :commonImport (textFrame, nil, nil),
-
- // ----------------------------------------------------------------------------------------
- // E X P O R T U T I L I T I E S
- // ----------------------------------------------------------------------------------------
- mapPhoneClassForExport: func (phoneClass)
- begin
- local exportClass := "Phone";
- local index := 0;
- loop
- begin
- if index >= Length(phoneClasses) then break;
- else
- begin
- if phoneClass = phoneClasses[index] then
- begin
- exportClass := editTypes.phoneType.choices[index];
- break;
- end;
- end;
- index := index + 1;
- end;
- return exportClass;
- end,
-
- exportCardType: func (cardType)
- begin
- local result := nil;
- if cardType then
- begin
- if cardType < Length(editTypes.cardType.choices) then
- result := editTypes.cardType.choices[cardType];
- end;
- return result;
- end,
-
- exportText: func (data)
- begin
- local result := nil;
- if data then
- begin
- // First make an array of the text slot indexes in the order of the top value in the viewbounds
- // Need to do this because the paragraphs are stored in the array in the order the user enters them,
- // not in the top to bottom order I want.
- local tops := [];
- foreach index, datum in data do
- if (datum.text Exists) and not datum.copyProtection then
- AddArraySlot (tops, {top: datum.viewbounds.top, index: index});
- Sort(tops, '|<|, 'top);
-
- foreach which in tops do
- begin
- theText := data[which.index].text;
- if result then
- result := Stringer([result, "\n", theText]);
- else
- result := theText;
- end;
- end;
- if not result then
- result := "";
- return result;
- end,
-
- // ----------------------------------------------------------------------------------------
- // E X P O R T
- // ----------------------------------------------------------------------------------------
- commonExport: func( soupFrame, store )
- begin
- local textFrame, i, numPhones;
-
- textFrame := {originalFrame: soupFrame};
- if (soupFrame.sorton) then
- textFrame.sorton := :getSortonString(ClassOf(soupFrame.sorton));
-
- local temp := :exportCardType (soupFrame.cardType);
- if temp then
- textFrame.cardType := temp;
-
- if (soupFrame.labels) then
- if store = nil then
- textFrame.labels := SPrintObject (soupFrame.labels);
- else
- textFrame.labels := GetFolderName(store, soupFrame.labels);
-
- if (soupFrame.name) then
- begin
- if (soupFrame.name.first) then
- textFrame.firstname := soupFrame.name.first;
- if (soupFrame.name.last) then
- textFrame.lastname := soupFrame.name.last;
- if (soupFrame.name.honorific) then
- textFrame.honorific := soupFrame.name.honorific;
- if (soupFrame.name.title) then
- textFrame.title := soupFrame.name.title;
- end;
-
- if (soupFrame.company) then
- textFrame.company := soupFrame.company;
-
- if (soupFrame.address) then
- textFrame.address := soupFrame.address;
-
- if (soupFrame.address2) then
- textFrame.address2 := soupFrame.address2;
-
- if (soupFrame.city) then
- textFrame.city := soupFrame.city;
-
- if (soupFrame.region) then
- textFrame.region := soupFrame.region;
-
- if (soupFrame.postal_code) then
- textFrame.postalcode := soupFrame.postal_code;
-
- if (soupFrame.country) then
- textFrame.country := soupFrame.country;
-
- if (soupFrame.email) then
- textFrame.email := soupFrame.email;
-
- if (soupFrame.phones) then
- begin
- numPhones := Length(soupFrame.phones);
- if (numPhones>0) then
- begin
- textFrame.phone1 := soupFrame.phones[0];
- textFrame.phone1type := :mapPhoneClassForExport(ClassOf(soupFrame.phones[0]));
- end;
- if (numPhones>1) then
- begin
- textFrame.phone2 := soupFrame.phones[1];
- textFrame.phone2type := :mapPhoneClassForExport(ClassOf(soupFrame.phones[1]));
- end;
- if (numPhones>2) then
- begin
- textFrame.phone3 := soupFrame.phones[2];
- textFrame.phone3type := :mapPhoneClassForExport(ClassOf(soupFrame.phones[2]));
- end;
- if (numPhones>3) then
- begin
- textFrame.phone4 := soupFrame.phones[3];
- textFrame.phone4type := :mapPhoneClassForExport(ClassOf(soupFrame.phones[3]));
- end;
- end;
-
- if not (soupFrame.bday = nil) then
- textFrame.birthday := ShortDateStr(soupFrame.bday, 0);
-
- if (soupFrame.notes Exists) then
- begin
- textFrame.notes := :exportText (soupFrame.notes);
- end;
-
- textFrame;
- end,
-
- tabExport: func( soupFrame, store )
- :commonExport ( soupFrame, store ),
-
- editExport: func( soupFrame, store )
- :commonExport ( soupFrame, store ),
-
- browserExport: func( soupFrame, store )
- :commonExport ( soupFrame, store ),
-
- // ----------------------------------------------------------------------------------------
- // V A L I D A T I O N
- // ----------------------------------------------------------------------------------------
- namesValidation: {
- company: {validType: 'string, nilOK: 'delete},
- address: {validType: 'string, nilOK: 'delete},
- address2: {validType: 'string, nilOK: 'delete},
- city: {validType: 'string, nilOK: 'delete},
- region: {validType: 'string, nilOK: 'delete},
- postal_code: {validType: 'string, nilOK: 'delete},
- country: {validType: 'string, nilOK: 'delete},
- email: {validType: 'string, nilOK: 'delete},
- phones: {validType: 'array, nilOK: 'delete},
- bday: {validType: 'int, nilOK: 'delete},
- labels: {validType: 'labels, nilOK: 'delete},
- sorton: {validType: 'string, nilOK: 'delete},
- cardType: {validType: 'int, nilOK: 'delete},
- notes: {validType: 'note, noteMaxWidth: 237, nilOK: 'delete},
- },
-
- nameValidation: {
- honorific: {validType: 'string, nilOK: 'delete},
- first: {validType: 'string, nilOK: 'delete},
- last: {validType: 'string, nilOK: 'delete},
- title: {validType: 'string, nilOK: 'delete},
- },
-
- namesParaFormat: {
- lineHeight: 18,
- maxRight: 237,
- defaultFontSpec: bor(tsFancy,tsSize(18)),
- maxBottom: 149,
- },
-
- entryValidation: func (toValidate, store)
- begin
- toValidate := ValidateSlots ("Names", toValidate, namesValidation);
- if IsFrame (toValidate) then
- begin
- if toValidate.name Exists then
- begin
- local result := ValidateSlots ("Names", toValidate.name, nameValidation);
- if IsFrame (toValidate.name) then
- toValidate.name := result;
- else
- toValidate := result;
- end;
- if IsFrame (toValidate) then
- begin
- // Do the special validation here
-
- // Make sure the class of sortOn is either company or name
- if toValidate.sorton Exists then
- if (ClassOf(toValidate.sorton) <> 'name) and (ClassOf(toValidate.sorton) <> 'company) then
- SetClass (toValidate.sorton, 'name);
-
- // Make sure the phone strings are really 'string
- if toValidate.phones Exists then
- begin
- foreach slot in toValidate.phones do
- begin
- if (not IsInstance(slot, 'string)) or
- (Length(slot) MOD 2 <> 0) or
- (ExtractWord (slot, Length(slot) - 2) <> 0) then
- return "a Names entry contained an invalid phone string";
- local found := nil;
- local slotClass := ClassOf(slot);
- foreach choice in phoneClasses do
- if choice = slotClass then
- begin
- found := true;
- break;
- end;
- if not found then
- return "a Names entry contained an invalid phone type";
- end;
- end;
-
- // Make sure the name frame has a class of 'person
- if toValidate.name Exists then
- SetClass (toValidate.name, 'person);
-
- if toValidate.notes <> nil then
- toValidate := ValidateNotes(toValidate, 'notes, namesParaFormat, store);
- end;
- end;
- return toValidate;
- end,
- };
-
-